﻿using Newtonsoft.Json;

namespace Micro.Extensions.Utilities
{
    /// <summary>
    /// 分页返回通用类
    /// </summary>
    public class AttachPage
    {
        /// <summary>
        /// 当前页
        /// </summary>
        public long PageIndex { get; set; }
        /// <summary>
        /// 每页条数
        /// </summary>
        public long PageSize { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonIgnore]
        public long Skip => (PageIndex - 1) * PageSize;
        /// <summary>
        /// 总条数
        /// </summary>
        public long TotalCount { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public long TotalPage
        {
            get
            {
                if (PageSize == 0)
                {
                    PageSize = 10;
                }
                var totalPage = TotalCount / PageSize;
                if (TotalCount % PageSize != 0) totalPage++;

                return totalPage;
            }
        }

        public AttachPage()
        {
            PageIndex = 1;
            PageSize = 10;
        }

        public AttachPage(long pageIndex, long pageSize)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
        }

        public AttachPage(long pageIndex, long pageSize, long totalCount)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = totalCount;
        }
    }


}
